/*     */ package nc.ui.bd.feature.ref.model;
/*     */ 
/*     */ import java.util.HashSet;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import java.util.Vector;
/*     */ import nc.bs.framework.common.NCLocator;
/*     */ import nc.pubitf.bd.feature.feature.IPubFeatureService;
/*     */ import nc.ui.bd.ref.AbstractRefModel;
/*     */ import nc.ui.bd.ref.IRefModelHandler;
/*     */ import nc.util.mmf.framework.base.MMValueCheck;
/*     */ import nc.vo.bd.feature.feature.entity.FeatureItemVO;
/*     */ import nc.vo.bd.feature.feature.enumeration.DataTypeEnum;
/*     */ import nc.vo.bd.feature.feature.message.MMBDLangConstFeature;
/*     */ import nc.vo.pub.BusinessException;
/*     */ import nc.vo.pubapp.pattern.exception.ExceptionUtils;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class FeatureValueRefModel
/*     */   extends AbstractRefModel
/*     */ {
/*     */   private String featureid;
/*     */   private Integer fdatatype;
/*     */   private static final String CODE = "code";
/*     */   
/*     */   public Integer getFdatatype()
/*     */   {
/*  31 */     return fdatatype;
/*     */   }
/*     */   
/*     */   public void setFdatatype(Integer fdatatype) {
/*  35 */     this.fdatatype = fdatatype;
/*     */   }
/*     */   
/*     */ 
/*     */   public String getFeatureid()
/*     */   {
/*  41 */     return featureid;
/*     */   }
/*     */   
/*     */   public void setFeatureid(String featureid) {
/*  45 */     this.featureid = featureid;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*  51 */   private final String[] fieldcode = { "vfvaluename" };
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  58 */   private final String[] fieldcodeForRef = { "code", "vfvaluename" };
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  65 */   private final String[] hiddendcode = { "cfeaturebid", "cfeatureid", "vfvalue" ,"vrowno"};
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  73 */   private final String[] fieldname = { MMBDLangConstFeature.getFEATVALUE() };
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  82 */   private final String[] fieldnameForRef = { MMBDLangConstFeature.getCODE_NAME(), MMBDLangConstFeature.getFEATVALUE() };
/*     */   
/*     */ 
/*     */ 
/*     */   public FeatureValueRefModel()
/*     */   {
/*  88 */     reset();
/*     */   }
/*     */   
/*     */   public void reset()
/*     */   {
/*  93 */     if (Integer.valueOf(DataTypeEnum.UFREF.toIntValue()).equals(fdatatype)) {
/*  94 */       setFieldCode(fieldcodeForRef);
/*  95 */       setFieldName(fieldnameForRef);
/*  96 */       setRefCodeField("code");
/*  97 */       setDefaultFieldCount(2);
/*     */     }
/*     */     else {
/* 100 */       setFieldCode(fieldcode);
/* 101 */       setFieldName(fieldname);
/* 102 */       setRefCodeField("vfvalue");
/* 103 */       setDefaultFieldCount(1);
/*     */     }
/* 105 */     setRefNodeName(MMBDLangConstFeature.getFEATVALUE());
/* 106 */     setHiddenFieldCode(hiddendcode);
/* 107 */     setPkFieldCode("cfeaturebid");
/* 108 */     setTableName(new FeatureItemVO().getTableName());
/* 109 */     setRefNameField("vfvaluename");
/* 110 */     setOrderPart("vrowno");
/*     */     
/*     */ 
/*     */ 
/* 114 */     resetFieldName();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public Vector getData()
/*     */   {
/* 127 */     String sql = getRefSql();
/*     */     
/* 129 */     Vector v = null;
/* 130 */     if (isCacheEnabled())
/*     */     {
/* 132 */       v = modelHandler.getFromCache(getRefDataCacheKey(), getRefCacheSqlKey());
/*     */     }
/*     */     
/* 135 */     if (v == null)
/*     */     {
/*     */ 
/*     */       try
/*     */       {
/*     */ 
/* 141 */         if (isFromTempTable()) {
/* 142 */           v = modelHandler.queryRefDataFromTemplateTable(sql);
/*     */         }
/*     */         else
/*     */         {
/* 146 */           v = getQueryResultVO();
/*     */         }
/*     */       }
/*     */       catch (Exception e)
/*     */       {
/* 151 */         ExceptionUtils.wrappException(e);
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 156 */     if ((v != null) && (isCacheEnabled()))
/*     */     {
/* 158 */       modelHandler.putToCache(getRefDataCacheKey(), getRefCacheSqlKey(), v);
/* 159 */       fillFValuename(v);
/*     */     }
/* 161 */     m_vecData = v;
/* 162 */     return m_vecData;
/*     */   }
/*     */   
/*     */   public String getRefSql()
/*     */   {
/* 167 */     String sql = super.getRefSql();
/* 168 */     if (Integer.valueOf(DataTypeEnum.UFREF.toIntValue()).equals(fdatatype)) {
/* 169 */       String pkDoc = "";
/* 170 */       if (sql.indexOf("cfeatureid=") > -1) {
/* 171 */         pkDoc = sql.substring(sql.indexOf("="));
/* 172 */         pkDoc = pkDoc.substring(pkDoc.indexOf("'") + 1, pkDoc.lastIndexOf("'"));
/*     */       }
/* 174 */       sql = "select  bd.code,bb.vfvaluename,bb.cfeaturebid,bb.cfeatureid,bb.vfvalue from bd_feature_b bb,bd_defdoc bd  where (bb.cfeatureid='" + pkDoc + "' and bb.dr = 0 and bb.vfvalue=bd.pk_defdoc) order by bb.vrowno";
/*     */     }
/*     */     
/*     */ 
/* 178 */     return sql;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void fillFValuename(Vector v)
/*     */   {
/* 187 */     Set<String> featureids = new HashSet();
/* 188 */     if (MMValueCheck.isEmpty(getFeatureid())) {
/* 189 */       for (int i = 0; i < v.size(); i++) {
/* 190 */         Vector inv = (Vector)v.get(i);
/* 191 */         featureids.add((String)inv.get(getFieldIndex("cfeatureid")));
/*     */       }
/*     */     }
/*     */     else {
/* 195 */       featureids.clear();
/* 196 */       featureids.add(getFeatureid());
/*     */     }
/* 198 */     IPubFeatureService fquery = (IPubFeatureService)NCLocator.getInstance().lookup(IPubFeatureService.class);
/*     */     try {
/* 200 */       Map<String, String> fvalue2name = fquery.getVFvalue2name((String[])featureids.toArray(new String[featureids.size()]));
/* 201 */       for (int i = 0; i < v.size(); i++) {
/* 202 */         Vector inv = (Vector)v.get(i);
/* 203 */         String featureid = inv.get(getFieldIndex("cfeatureid")).toString();
/*     */         
/* 205 */         String vfvalue = inv.get(getFieldIndex("vfvalue")).toString();
/* 206 */         inv.setElementAt(fvalue2name.get(featureid + vfvalue), getFieldIndex("vfvaluename"));
/*     */       }
/*     */     }
/*     */     catch (BusinessException e) {
/* 210 */       ExceptionUtils.wrappBusinessException(MMBDLangConstFeature.getERR_FOR_REF());
/*     */     }
/*     */   }
/*     */   
/*     */   protected String getLangStrSuffix()
/*     */   {
/* 216 */     return null;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public String getRefTitle()
/*     */   {
/* 226 */     return MMBDLangConstFeature.getFEATVALUE();
/*     */   }
/*     */ }

